package com.automation.ljf.converter;

import com.automation.ljf.domain.dataobject.CaseDO;
import com.automation.ljf.domain.dataobject.CaseReportDO;
import com.automation.ljf.domain.po.CasePO;
import com.automation.ljf.domain.request.CaseRequest;
import com.automation.ljf.domain.vo.CaseVO;
import com.automation.ljf.util.CommonUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * Case实体转换器
 *
 * @author lijiefeng
 * @since 2021/8/27
 */
@Component
public class CaseConvert {

    public CaseVO casePOToVO(CasePO casePO){
        if (casePO == null){
            return null;
        }
        CaseVO caseVO = new CaseVO();
        //PO转化为VO返回
        caseVO.setCaseId(casePO.getCaseId())
                .setCaseName(casePO.getCaseName())
                .setCaseDetail(casePO.getCaseDetail())
                .setCaseUrl(casePO.getCaseUrl())
                .setAdmUserId(casePO.getAdmUserId())
                .setCreateTime(casePO.getCreateTime())
                .setUpdateTime(casePO.getUpdateTime());
        return caseVO;
    }


    public CaseDO caseVOToDO(CaseVO caseVO){
        if (caseVO == null){
            return null;
        }
        CaseDO caseDO = new CaseDO();
        caseDO.setCaseId(caseVO.getCaseId())
                .setCaseName(caseVO.getCaseName())
                .setCaseDetail(caseVO.getCaseDetail())
                .setCaseUrl(caseVO.getCaseUrl())
                .setAdmUserId(caseVO.getAdmUserId());
        return caseDO;
    }

    //创建用例用的
    public CasePO caseDOToPO(CaseDO caseDO){
        if (caseDO == null){
            return null;
        }
        CasePO casePO = new CasePO();
        casePO.setId(CommonUtil.generateOID())
                .setCaseId(CommonUtil.generateOID())
                .setCaseName(caseDO.getCaseName())
                .setCaseUrl(caseDO.getCaseUrl())
                .setCaseDetail(caseDO.getCaseDetail())
                .setAdmUserId(caseDO.getAdmUserId())
                .setCreateTime(new Date())
                .setUpdateTime(new Date());
        return casePO;
    }
    //修改用例用的
    public CasePO caseDOToPOUpdate(CaseDO caseDO){
        if (caseDO == null){
            return null;
        }
        CasePO casePO = new CasePO();
        BeanUtils.copyProperties(caseDO, casePO);
        casePO.setUpdateTime(new Date());
        return casePO;
    }


    public CaseDO casePOToDO(CasePO casePO){
        if (casePO == null){
            return null;
        }
        CaseDO caseDO = new CaseDO();
        BeanUtils.copyProperties(casePO, caseDO);
        return caseDO;
    }

    public CaseReportDO caseDOToCaseReportDO(CaseDO caseDO){
        if (caseDO == null){
            return null;
        }
        CaseReportDO caseReportDO = new CaseReportDO();
        caseReportDO.setCaseId(caseDO.getCaseId())
                .setCaseName(caseDO.getCaseName())
                .setCaseDetail(caseDO.getCaseDetail())
                .setCaseUrl(caseDO.getCaseUrl())
                .setAdmUserId(caseDO.getAdmUserId());
        return caseReportDO;
    }

    public CaseDO caseRequestToCaseDO(CaseRequest caseRequest){
        CaseDO caseDO = new CaseDO();
        BeanUtils.copyProperties(caseRequest, caseDO);
        return caseDO;
    }

}
